package com.hhp.cloud.shop.product.controller;

import java.util.Arrays;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hhp.cloud.shop.product.entity.SpuInfoDescEntity;
import com.hhp.cloud.shop.product.service.SpuInfoDescService;
import com.hhp.cloud.shop.common.core.result.R;



/**
 * spu信息介绍
 *
 * @author hhp
 * @email 2437579794@qq.com
 * @date 2021-12-07 15:15:44
 */
@RestController
@RequestMapping("/api/v1/product/spuInfoDesc")
public class SpuInfoDescController {
    @Autowired
    private SpuInfoDescService spuInfoDescService;

    /**
     * 列表
     */
    @ApiOperation(value = "spu信息介绍分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "spuId", value = "商品id", paramType = "query", dataType = "Long")
    })
    @GetMapping
    public R list(Integer page, Integer limit, Long spuId){
        return R.ok().setData(spuInfoDescService.pageMaps(
                new Page<>(page, limit),
                new LambdaQueryWrapper<SpuInfoDescEntity>()
                        .eq(ObjectUtil.isNotNull(spuId), SpuInfoDescEntity::getSpuId, spuId)));
    }


    /**
     * 信息
     */
    @ApiOperation(value = "spu信息介绍详情")
    @ApiImplicitParam(name = "spuId", value = "商品id", required = true, paramType = "path", dataType = "Long")
    @GetMapping("/{spuId}")
    public R info(@PathVariable("spuId") Long spuId){
		return R.ok().setData(spuInfoDescService.getById(spuId));
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增spu信息介绍")
    @PostMapping
    public R save(@RequestBody SpuInfoDescEntity spuInfoDesc){
		spuInfoDescService.save(spuInfoDesc);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改spu信息介绍")
    @PutMapping("/{spuId}")
    public R update(@PathVariable("spuId") Long spuId, @RequestBody SpuInfoDescEntity spuInfoDesc){
		spuInfoDescService.updateById(spuInfoDesc);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除spu信息介绍")
    @DeleteMapping
    public R delete(@RequestBody Long[] spuIds){
		spuInfoDescService.removeByIds(Arrays.asList(spuIds));

        return R.ok();
    }

}
